package com.cy.milktea.service.impl;

import com.cy.milktea.common.annotation.SetUserAndTime;
import com.cy.milktea.mapper.StockMapper;
import com.cy.milktea.pojo.Stock;
import com.cy.milktea.service.StockService;
import com.cy.milktea.utils.PageHelperUtils;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;


@Service
public class StockServiceImpl implements StockService {

    @Autowired
    private StockMapper stockMapper;

    @SetUserAndTime
    @Override
    public void add(Stock stock) {
        stockMapper.insert(stock);
    }

    @Override
    public void delete(Integer id) {
        stockMapper.delete(id);
    }

    @SetUserAndTime("modify")
    @Override
    public void update(Stock stock) {
        stockMapper.update(stock);
    }

    @Override
    public PageInfo<Stock> query(String name, Date date, String sort) {
        return PageHelperUtils.startPage().doSelectPageInfo(() -> stockMapper.select(name, date, sort));
    }
}
